<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<div class="gv-forms gv-forms-fluid" layout="column">
  <div class="gv-forms-header">
    <h1 ng-if="!$ctrl.editMode">New dashboard [{{$ctrl.dashboard.reference_type}}]</h1>
    <h1 ng-if="$ctrl.editMode">{{::$ctrl.dashboard.name}} [{{$ctrl.dashboard.reference_type}}]</h1>
    <a ui-sref="management.settings.analytics">Back to dashboards</a>
  </div>

  <form name="$ctrl.formDashboard" ng-submit="$ctrl.save()" novalidate>
    <div class="gv-form">
      <h2>Details</h2>
      <div class="gv-form-content" layout="column">
        <div layout="row" layout-align="end center">
          <md-input-container flex>
            <label>Dashboard name</label>
            <input ng-model="$ctrl.dashboard.name" required />
          </md-input-container>

          <md-input-container>
            <md-checkbox ng-model="$ctrl.dashboard.enabled">Enabled dashboard</md-checkbox>
          </md-input-container>
        </div>

        <div layout="row" layout-align="end center">
          <md-input-container flex>
            <label>Query filter</label>
            <input type="text" ng-model="$ctrl.dashboard.query_filter" />
          </md-input-container>

          <ng-md-icon
            icon="info"
            style="fill: #b1bdc5"
            aria-label="Query filter info"
            ng-click="$ctrl.showQueryFilterInformation()"
          ></ng-md-icon>

          <md-input-container ng-if="$ctrl.displayPreview()">
            <md-button type="button" ng-if="$ctrl.updateMode" class="md-raised md-primary" ng-click="$ctrl.tooglePreview()">
              <ng-md-icon icon="play_arrow" style="fill: white"></ng-md-icon>Enable preview
            </md-button>
            <md-button type="button" ng-if="!$ctrl.updateMode" class="md-raised md-warn" ng-click="$ctrl.tooglePreview()">
              <ng-md-icon icon="stop" style="fill: white"></ng-md-icon>Disable preview
            </md-button>
          </md-input-container>
        </div>

        <gv-dashboard model="$ctrl.dashboard" update-mode="$ctrl.updateMode"></gv-dashboard>

        <md-card-actions layout="row" ng-if="$ctrl.updateMode">
          <md-button
            type="submit"
            class="md-raised md-primary"
            permission
            permission-only="['environment-dashboard-c', 'environment-dashboard-u']"
            ng-disabled="$ctrl.formDashboard.$invalid || $ctrl.formDashboard.$pristine"
          >
            Save
          </md-button>
          <md-button
            type="button"
            class="md-raised"
            permission
            permission-only="['environment-dashboard-c', 'environment-dashboard-u']"
            ng-click="$ctrl.reset()"
            ng-disabled="$ctrl.formDashboard.$pristine"
          >
            Reset
          </md-button>
        </md-card-actions>
      </div>
    </div>
  </form>
</div>

<md-button
  permission
  permission-only="['environment-dashboard-c', 'environment-dashboard-u']"
  ng-if="$ctrl.updateMode"
  aria-label="Add widget"
  class="md-fab md-fab-bottom-right md-fab-scrollable"
  ng-class="{'gv-help-displayed': $ctrl.$rootScope.helpDisplayed}"
  ng-click="$ctrl.addWidget()"
>
  <md-tooltip md-direction="top" md-visible="false">Add a new widget</md-tooltip>
  <ng-md-icon icon="add"></ng-md-icon>
</md-button>
